﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace WCS.Infrastructure.EFCore;

/// <summary>
/// 优惠券实例表
/// </summary>
[Table("CouponInstance")]
[Index("InstanceCode", Name = "CouponInstance_InstanceCode_idx", IsUnique = true)]
[Index("TemplateId", "ActivationExpirationTime", Name = "CouponInstance_TemplateId_ActivationExpirationTime_idx")]
[Index("TemplateId", "AvailableEndTime", Name = "CouponInstance_TemplateId_AvailableEndTime_idx")]
[Index("TemplateId", "Status", Name = "CouponInstance_TemplateId_Status_idx")]
[Index("TemplateId", Name = "CouponInstance_TemplateId_idx")]
[Index("UserId", "TemplateId", Name = "CouponInstance_UserId_TemplateId_idx")]
public partial class CouponInstance
{
    /// <summary>
    /// 优惠券实例ID
    /// </summary>
    [Key]
    [StringLength(32)]
    public string Id { get; set; } = null!;

    /// <summary>
    /// 优惠券实例编号
    /// </summary>
    [StringLength(32)]
    public string InstanceCode { get; set; } = null!;

    /// <summary>
    /// 关联模板ID
    /// </summary>
    [StringLength(32)]
    public string TemplateId { get; set; } = null!;

    /// <summary>
    /// 领取用户ID
    /// </summary>
    [StringLength(32)]
    public string UserId { get; set; } = null!;

    /// <summary>
    /// 可使用开始时间：由模板的生效延迟类型（EffectiveDelayType）与有效期类型（ValidityType）组合计算；当有效期为固定范围（ValidityType=1）时，取 Max(延迟生效时间, 模板固定有效期开始时间)；当有效期为相对时长（ValidityType=2）时，取延迟生效后的时间点作为开始时间。
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime AvailableStartTime { get; set; }

    /// <summary>
    /// 可使用结束时间：当有效期为固定范围（ValidityType=1）时，取模板固定有效期结束时间；当有效期为相对时长（ValidityType=2）时，取 AvailableStartTime + 模板有效期时长（小时）。
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime AvailableEndTime { get; set; }

    /// <summary>
    /// 扩展属性
    /// </summary>
    public string? ExtraProperties { get; set; }

    /// <summary>
    /// 并发控制标记
    /// </summary>
    [StringLength(40)]
    public string? ConcurrencyStamp { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 状态：0=未激活，1=未使用，2=已使用，3=已过期，4=已冻结
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    /// 推荐商户ID
    /// </summary>
    [StringLength(32)]
    public string? RecommendMerchantId { get; set; }

    /// <summary>
    /// 用户在同一微信开放平台账号下所有应用（包括小程序、公众号等）的全局唯一标识
    /// </summary>
    [StringLength(255)]
    public string? UnionId { get; set; }

    /// <summary>
    /// 所属商户ID
    /// </summary>
    [StringLength(32)]
    public string MerchantId { get; set; } = null!;

    /// <summary>
    /// 所属门店ID
    /// </summary>
    [StringLength(32)]
    public string? StoreId { get; set; }

    /// <summary>
    /// 所属收款码ID
    /// </summary>
    [StringLength(32)]
    public string? CodeId { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remarks { get; set; }

    /// <summary>
    /// 抽奖活动ID
    /// </summary>
    [StringLength(32)]
    public string? ActivityId { get; set; }

    /// <summary>
    /// 激活过期时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? ActivationExpirationTime { get; set; }

    /// <summary>
    /// 最后修改人ID
    /// </summary>
    [StringLength(32)]
    public string? LastModifierId { get; set; }

    /// <summary>
    /// 最后修改时间
    /// </summary>
    [Column(TypeName = "timestamp(6) without time zone")]
    public DateTime? LastModificationTime { get; set; }
}
